using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Globalization;
using System.Reflection;
using System.Threading;

using WillStott.MxAppToolbox;


namespace TestApp
{
    public class TestWinApp : Program
    {
		private bool         m_MainFormClosing;
		private UniMsgList   m_UniMsgList;
		private UniLog       m_UniEventLog;
        private bool         m_VerboseLog;
        private string       m_helpFilePathName;

		private TestWinApp() {}
		static TestWinApp()
		{
			try
			{
				Program.Instance = new TestWinApp();
				TestWinApp.Instance.m_MainFormClosing = true;	//reset in MainFrom when it is open
				
				TestWinApp.Instance.m_UniEventLog = new UniLog();
                TestWinApp.Instance.m_VerboseLog = true;
				TestWinApp.Instance.m_UniEventLog.Name = "TestWinApp";
			}
			catch (Exception e)
			{		//unless you end the program here a TypeInitializationException is thrown as the ctor failed
				Program.FatalErrorAbend("TestApp.TestWinApp()", e.Message);
			}
		}
		static public new TestWinApp Instance {	get { return Program.Instance as TestWinApp; }}

        public override bool VerboseLog
        {
            get { return m_VerboseLog; }
            set { m_VerboseLog = value; }
        }

        public override string HelpFilePathName 
        { 
            get { return m_helpFilePathName; } 
            set { m_helpFilePathName = value; } 
        }
		public override UniLog AppLog {	get { return m_UniEventLog; }}
		public override  UniMsgList	ErrMsgs { get { return m_UniMsgList; }}	
		public override bool MainFormClosing
		{ 
			get { return m_MainFormClosing; }
			set { m_MainFormClosing = value; }
		}
		public override bool CloseAllDocuments(bool AllowCancel)
		{
			bool rc = true;
			if ( (AllowCancel == true) && (MessageBox.Show("Close now?", "Msg", MessageBoxButtons.YesNo) == DialogResult.No ))
				rc = false;
			return rc;
		}
        public override void MainArgProc(string[] args)
        {
            if (args.Length > 0)
            {
                if (args[0] == "/culture=DE")
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo("de");
            }
            Assembly resAsm = Program.GetResourceAssembly(this);
            TestWinApp.Instance.m_UniMsgList = UniMsgList.LoadList(resAsm, "TestApp.TestWinAppMsg.xml");
            HelpFilePathName = Utils.GetPath(resAsm.Location) + "TestApp.chm";
        }
 
        [STAThread]
        static void Main(string[] args)
        {
            TestWinApp.Instance.MainArgProc(args);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());

        }
    }
}